import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { CristmasToyModelEnum } from "../../../public/GameEnumConfig";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";
import Player from "../../player/Player";
/**
* 圣诞树装饰
**/
export default class CristmasToyModel extends DataItemModel {

	static CLASS_NAME: string = 'CristmasToyModel'

	init(id, data) {
		super.init(id, data)
		this.state = User.instance().getTreeToyState(this.ID)
	}

	setState(s) {
		super.setState(s)
		User.instance().setTreeToyState(this.ID, s)
	}
	// icon
	getIcon() {
		return 'texture/cristmas/' + this.data[CristmasToyModelEnum.icon]
	}
	// 消费道具
	getCostItem() {
		return this.data[CristmasToyModelEnum.costItem]
	}

	getIndex() {
		return this.data[CristmasToyModelEnum.index]
	}
	getOpenLevel() {
		let num = this.data[CristmasToyModelEnum.adge]
		return num ? num : 0
	}
	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel();
	}
	needBuy() {
		let cost: number[] = this.getCostItem()
		return cost && cost.length > 0 && this.getState() != ItemState.GOT
	}

	use() {
		User.instance().setToyTypeData(this.getIndex(), this.ID)
	}

	unuse() {
		User.instance().setToyTypeData(this.getIndex(), 0)
	}

}